package com.yanggu.bigdata.realtime.app.function

import com.yanggu.bigdata.realtime.utils.KeywordUtil
import org.apache.flink.table.annotation.{DataTypeHint, FunctionHint}
import org.apache.flink.table.functions.TableFunction
import org.apache.flink.types.Row


/**
 * https://nightlies.apache.org/flink/flink-docs-release-1.14/docs/dev/table/functions/udfs/#table-functions
 *
 */
//scala使用java的注解需要使用new来创建一个新的注解
@FunctionHint(output = new DataTypeHint("ROW<s STRING>"))
class KeywordUDTF extends TableFunction[Row] {

  def eval(value: String): Unit = {
    val keywordList = KeywordUtil.analyze(value)
    for (keyword <- keywordList) {
      val row = new Row(1)
      row.setField(0, keyword)
      collect(row)
    }
  }

}
